import {request} from "@umijs/max";
import {covertTableData} from "@/utils/tableUtil";
import {USER} from "@/services/admin/typings";

export const fetchUserPage = async (params: USER.FetchUserPage) => {
  const resp = await request<USER.Response>('/api/user/page', {
    method: 'GET',
    params
  })
  return covertTableData(resp)
}

export const getUserList = async (params?: { userName: string }) => {
  return request<USER.UserVO[]>('/api/user/list', {params})
}


export const addUser = async (dto: USER.UpdateDTO) => {
  return request<USER.UserVO>('/api/user/save', {
    method: 'POST',
    data: dto
  })
}


export const updateUser = async (dto: USER.UpdateDTO) => {
  return request<USER.UserVO>('/api/user/update', {
    method: 'POST',
    data: dto
  })
}

export const deleteUser = async (id: number) => {
  return request<USER.UserVO>(`/api/user/delete?id=${id}`, {
    method: 'POST',
  })
}
export const getUserListByRoleKey = async (roleKey: string) => {
  return request<USER.UserVO[]>(`/api/user/getUserListByRoleKey?roleKey=${roleKey}`)
}
